<?php

/**
 * 
 * @author yuxun
 *
 */
class MatchCrossServerService extends Service{

    public static function indexHeader(){
        $header = array(
                'id'            => array('text' => '序号', 'width' => '80px'),
        		'cross_server_name'       => array('text' => '跨服名称', 'width' => '150px'),
                'server_list'   => array('text' => '包含服务器', 'width' => '300px'),
        		'node_name'     => array('text' => '节点名称', 'width' => '150px'),
        		'develop_id'    => array('text' => '开发ID', 'width' => '100px'),
        		'version'       => array('text' => '版本', 'width' => '60px'),
        		'ip'            => array('text' => 'IP', 'width' => '100px'),
        		'port'          => array('text' => '端口', 'width' => '80px'),
        		'create_time'   => array('text' => '生效时间', 'width' => '150px'),
                //'action'        => array('text' => '操作', 'width' => '60px'),
        );

        return $header;
    }
    
    public static function indexData($params){   	
    	$modMatchCrossServer = new ModMatchCrossServer();
        $result = $modMatchCrossServer->page($params);
    	$length = count($result['data']);
    	foreach($result['data'] as $k=>&$v){
    		$type = 1;
    		if($k == 0 && $length == 1){  //当前页只剩下一条数据时，删除之后需显示上一页的数据
    			$type = 2;
    		}  
    		$server_list =  self::getServer($v['id']); 		
    		$v['server_list'] = $server_list == ''? '':$server_list;
    	    $v['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
    	}
    	unset($v);
    
    	return $result;
    }
    
    public static function getServer($id){  	
    	$modMatchCrossSer = new ModMatchCrossSer();
    	$serverData = $modMatchCrossSer->getServer($id);
    	$list = '';
    	foreach ($serverData as $key=>$val){
    		$list .= ','.$val['server_name'].'('.$val['server_num'].')';
    	}
    	$list = substr($list, 1);
    	return $list;
    }
    
}